package com.baoxin.chenxixc4coach.utils;


public class TimeTools {

    final static long DAY = 24 * 60 * 60 * 1000;
    final static long HOUR = 60 * 60 * 1000;
    final static long MIN = 60 * 1000;
    final static long SECOND = 1000;

    public static String getHHmmssByLong(long timePeriod) {

        long day = 0, hour = 0, minute = 0, second = 0;

        day = timePeriod / DAY;
        hour = (timePeriod - DAY * day) / HOUR;
        minute = (timePeriod - DAY * day - HOUR * hour) / MIN;
        second = (timePeriod - DAY * day - HOUR * hour - MIN * minute) / SECOND;

        StringBuilder sb = new StringBuilder();

//        if (day > 0) {
//            sb.append(day).append("天");
//        } else {
//            sb.append("0").append("天");
//        }

        if (hour < 10) {
            sb.append("0").append(hour).append(":");
        } else {
            sb.append(hour).append(":");
        }
        if (minute < 10) {
            sb.append("0").append(minute).append(":");
        } else {
            sb.append(minute).append(":");
        }
        if (second < 10) {
            sb.append("0").append(second);
        } else {
            sb.append(second);
        }
        return sb.toString();
    }

    /**
     * @param timePeriod 验证倒计时，60s之内
     * @return
     */
    public static String getSecondByLong(long timePeriod) {
        long SECOND = 1000;
        long day = timePeriod / DAY;
        long hour = (timePeriod - day * DAY) / HOUR;
        long min = (timePeriod - day * DAY - hour * HOUR) / MIN;
        long second = (timePeriod - day * DAY - hour * HOUR - min * MIN) / SECOND;

        StringBuilder sb = new StringBuilder();

        if (second < 10) {
            sb.append("0").append(second);
        } else {
            sb.append(second);
        }
        sb.append("S");
        return sb.toString();
    }

}
